Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix react-native-macos-init to not break react-native-windows-init #317

Merged
merged 11 commits into from
Apr 23, 2020

Conversation

tom-un
Copy link
Collaborator

@tom-un tom-un commented Apr 23, 2020

Please select one of the following

  • I am removing an existing difference between facebook/react-native and microsoft/react-native 👍
  • I am cherry-picking a change from Facebook's react-native into microsoft/react-native 👍
  • I am making a fix / change for the macOS implementation of react-native
  • I am making a change required for Microsoft usage of react-native

When react-native-windows-init modifies a project, it adds a react-native.config.js file. When react-native-macos-init modifies a project, it also adds a react-native.config.js file wiping out any previous contents.

This change make it such that the macOS requirements are appended to an existing react-native.config.js if one already exists, or creates a new one.

react-native-windows-init creates a config with the contents:

const fs = require('fs');
const path = require('path');
module.exports = {
  reactNativePath:  fs.realpathSync(path.resolve(require.resolve('react-native-windows/package.json'), '..')),
};

react-native-macos-init will now append:

const macSwitch = '--use-react-native-macos';
if (process.argv.includes(macSwitch)) {
  process.argv = process.argv.filter(arg => arg !== macSwitch);
  process.argv.push('--config=metro.config.macos.js');
  module.exports = {
    reactNativePath: 'node_modules/react-native-macos',
  };
}

The react-native-windows-init package will need a similar change to prepend its required contents to react-native.config.js. When it does this, then react-native-macos-init can be run before react-native-windows-init and vis versa.

Note: The need for react-native.config.js at all in either windows or macOS projects is temporary: when both projects are at react-native 0.62 and react-native-community/cli#1115 lands, then both projects can use npmPackageName instead.

Focus areas to test

The script was tested against project folder with and without pre-existing react-native.config.js files.

Microsoft Reviewers: Open in CodeFlow

@tom-un tom-un requested a review from acoates-ms as a code owner April 23, 2020 03:22
@pull-bot
Copy link

Messages
📖

📋 Missing Changelog - Can you add a Changelog? To do so, add a "## Changelog" section to your PR description. A changelog entry has the following format: [CATEGORY] [TYPE] - Message.

CATEGORY may be:
  • General
  • iOS
  • Android
  • JavaScript
  • Internal (for changes that do not need to be called out in the release notes)

TYPE may be:

  • Added, for new features.
  • Changed, for changes in existing functionality.
  • Deprecated, for soon-to-be removed features.
  • Removed, for now removed features.
  • Fixed, for any bug fixes.
  • Security, in case of vulnerabilities.

MESSAGE may answer "what and why" on a feature level. Use this to briefly tell React Native users about notable changes.

📖 📋 Missing Test Plan - Can you add a Test Plan? To do so, add a "## Test Plan" section to your PR description. A Test Plan lets us know how these changes were tested.
📖 📋 Missing Summary - Can you add a Summary? To do so, add a "## Summary" section to your PR description. This is a good place to explain the motivation for making this change.

Generated by 🚫 dangerJS against 70a5ee3

@tom-un tom-un requested review from 13thsymphony, HeyImChris and alloy and removed request for 13thsymphony April 23, 2020 14:41
@tom-un tom-un merged commit 6249f69 into microsoft:master Apr 23, 2020
@tom-un tom-un deleted the tomun/cli-append-config branch May 8, 2020 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants